import { createRouter, createWebHistory } from 'vue-router'
//导入跳转路由组件
import TeacherLogin from '../components/TeacherLogin.vue'
import TeacherPage from '../components/TeacherPage.vue'
import TeacherScore from '../components/TeacherScore.vue'
import TeacherSubjectManger from '../components/TeacherSubjectManger.vue'
import TeacherClasses from '../components/TeacherClasses.vue'
import TeacherExamination from '../components/TeacherExamination.vue'
//Teacher端
import {teacherStateStore} from "../store/TeacherInfo.js"



//路由编写

const router = createRouter({
    history: createWebHistory(),
    routes: [
        {
            path: "/",
            components: {
                TeacherRouter: TeacherLogin
            }
        },
        {
            path: "/login",
            components: {
                TeacherRouter: TeacherLogin
            }
        },
        {
            path: "/page",
            components: {
                TeacherRouter: TeacherPage
            },
            children: [

                {
                    path: "/page/teacher/classes",
                    components: {
                        TeacherPageRouter: TeacherClasses
                    }
                },
                {
                    path: "/page/teacher/score",
                    components: {
                        TeacherPageRouter: TeacherScore
                    }
                },
                {
                    path: "/page/teacher/subject",
                    components: {
                        TeacherPageRouter: TeacherSubjectManger
                    }
                }, {
                    path: "/page/teacher/examination",
                    components: {
                        TeacherPageRouter: TeacherExamination
                    }
                }

            ]
        },
    ]
})
//路由控制页面的跳转
router.beforeEach(
    (to, from, next) => {
        const teapcher = teacherStateStore();
        //路由跳转
        if (to.path == "/login" || to.path == "/") {
            //登录页面放行
            next();
        }
        if (to.path == "/page"||
            to.path == "/page/teacher/classes" ||
            to.path == "/page/teacher/score" ||
            to.path == "/page/teacher/subject" ||
            to.path == "/page/teacher/examination" 
        ) {
            if (teapcher.getterTeacherteacherLoginState == 1) {
                next()
            }
        }


    }
)

export default router;//路由